home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_22_1988_Transactor_Publishing.d64 / sort demo update (.txt) < prev    next >
Commodore BASIC  |  2023-02-26  |  639b  |  27 lines

  1. 10 input"how many names";n
  2. 20 dim a(n),b(n),a$(n),t$(n)
  3. 30 for j=1 to n: print: print"number";j
  4. 40 input"surname";s$
  5. 50 input"first name";f$
  6. 60 t$(j)=s$+", "+f$: rem combine surnames with last names
  7. 70 input"age";a$(j)
  8. 80 h=(j-1)/2: g=0
  9. 82 if (t$(j) < t$(a(h))) then h=int((h+g)/2): goto 86
  10. 84 g=h: h=int((h+j)/2)
  11. 86 if h-g > 0 then 82
  12. 88 h=h-(t$(j) > t$(a(h))): g=j-1
  13. 90 if g>=h then a(g+1)=a(g): g=g-1: goto 90
  14. 100 a(h)=j
  15. 110 b(j)=j: h=j+1
  16. 120 h=h-1: if a$(j)<a$(b(h-1))then b(h)=b(h-1): goto 120: rem sort ages
  17. 130 b(h)=j
  18. 140 next j
  19. 150 print: print"sorted alphabetically"
  20. 160 for j=1 to n
  21. 170 print t$(a(j)), a$(a(j))
  22. 180 next j
  23. 190 print:print" sorted by age:"
  24. 200 for j=1 to n
  25. 210 print t$(b(j)), a$(b(j))
  26. 220 next j
  27.